Skip to content

Allow custom annotations for MCP elements #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Clap404
Copy link

@Clap404 Clap404 commented Jul 31, 2025

I'd like to use custom annotations that extends the ones provided by php-mcp.

I've discovered that some of the annotations I'd like to inherit were final and that the provided Discoverer would not match subclasses of the annotations. I'm not sure if it's accidental or by design.

This change would allow me to use the default Discoverer with custom annotations instead of making my own.

@judus
Copy link
Contributor

judus commented Jul 31, 2025

Out of curiosity — may I ask what concrete use case you’re trying to support with this?

I’ve been exploring this area myself, and I might be misunderstanding something, but from what I can tell, the MCP server maintains a fairly static registry. Either through attribute discovery or manual registration. The container seems focused on injecting dependencies into tool handlers, not on dynamically filtering or scoping tools — which makes sense, given how shallow PSR-11 is.

So if this PR is about enabling more dynamic resolution, I’m wondering whether this kind of logic really belongs at the attribute level or whether we might eventually need a more expressive registry or tool resolution layer instead?

If the goal is extensibility via attributes, I’d lean toward defining interfaces rather than relying on inheritance. That might offer a cleaner extension point while keeping the existing classes final and predictable.

@CodeWithKyrian
Copy link
Contributor

Hey, thanks for putting this up.

I get the motivation for wanting to extend the MCP attribute classes, but I’m not really seeing a practical use case for it in the context of how the MCP server works right now. The core attributes like McpTool, McpResource, McpPrompt, and McpResourceTemplate are really just a way for the Discoverer to pick up the standard MCP elements. The properties they expose (name, description, mimeType, etc.) are all pretty much dictated by the MCP spec and are meant to be consistent across the board.

If you want to add extra metadata or annotations for your own app’s needs (like say, custom scopes or tags), it’s actually cleaner to define your own attribute for that and then use reflection in your own code to read and act on those. The Discoverer isn’t going to know or care about those extra properties anyway, since it’s only looking for the standard MCP stuff. It doesn’t even have any hooks or extension points for custom properties 🤷🏽‍♂️

If the MCP spec ever adds new fields or requirements, we can always update the core attributes and the Discoverer to support those. But for app-specific stuff, custom attributes and your own reflection logic are the way to go.

So, I’m leaning toward keeping these classes final for now, just to keep things predictable and in line with the spec. If there’s a really compelling use case for subclassing that I’m missing, I’m open to hearing it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants